Adam Zheng, Product Manager
TensorRT LLM 旨在帮助用户在 NVIDIA AI 平台上获得大型语言模型(LLM)推理部署的最佳性能。
新架构旨在通过与现有 LLM API 相同的接口,更轻松地扩展系统以支持新模型和新功能。
当前架构的挑战:
* 新模型需要手动重新实现: 需要使用 TensorRT-LLM Layer API 重写架构,并编写自定义的权重加载脚本。
* 添加新功能需要深入的系统知识: 必须理解整个紧密耦合的系统才能进行微小修改,且大多数更改必须在 C++ 中实现。
* 引擎构建限制开发速度: 在修改构建参数或升级运行时版本时,需要等待漫长的引擎构建时间。
重构后的新架构优势:
* 复用 PyTorch 实现以支持新模型: 直接复制 PyTorch 模型实现,并将关键组件替换为预构建的、包含优化内核的 torch 自定义操作(custom ops)包装器,以进一步提升性能。
* 在模块化的 Python 中构建新功能: 清晰定义的 Python 接口,用于核心运行时构建块,以实现最大的可定制性(hackability)。
* 无需构建引擎即可快速迭代: 前向传播过程在 PyTorch 中执行,无需(重新)构建引擎。
在传统的 TensorRT 工作流程中,不能直接加载 HuggingFace 格式的 checkpoint 并运行。需要通过手动运行脚本来执行两个额外步骤:
1. 转换 Checkpoint: 准备一个与 TensorRT-LLM 中模型定义兼容的 checkpoint。
2. 构建引擎: 准备一个可运行的 TensorRT 引擎的二进制文件。
下图展示了从 HuggingFace Checkpoint 到最终运行 TRT 引擎的数据流和使用流程。
新版 LLM API 提供了基于 PyTorch 的建模支持,带来了显著的易用性提升:
* 无需转换 checkpoint: 模型定义与 vLLM/SGLang 或 HF transformers 类似,与 HF checkpoints 兼容。
* 无需构建引擎: 模型执行也基于 PyTorch。
* 统一的入口点: PyTorch 工作流的入口点也是 LLM API。
* 用户体验更好: 对用户更友好,易于修改和调试。
新架构显著减少了代码量,并简化了工作流程。
旧版 TensorRT-LLM:
* tensorrt_llm/models/llama/model.py: ~600 LoC
* LLAMADecoderLayer: ~200 LoC
* LLAMAModel: ~100 LoC
* LLAMAForCausalLM: ~200 LoC
* 需要将 HF key 转换为 TRT-LLM key,量化(模块替换)等操作使代码更长。
tensorrt_llm/models/llama/convert.py: ~2500 LoC
examples/llama/convert_checkpoint.py: ~600 LoC
新版基于 PyTorch 的 TensorRT-LLM:
tensorrt_llm/_torch/models/modeling_llama.py: ~200 LoC
无需额外的 checkpoint 转换代码:
注: 这不是一个精确的苹果对苹果的比较。例如,convert.py 中的 2500 LoC 包含许多不由 TRT 工作流使用的遗留代码。但这只是为了展示 PyTorch 工作流的代码库要干净得多。
PyTorch 的 Eager 模式执行使调试变得更加容易。
在 TRT 模块中:
trtllm-build --enable_debug_output 等标志来构建 TRT 引擎。在 PyTorch 模块中:
下图显示,基于 PyTorch 的新路径在吞吐量性能上与传统的 TRT 路径相当。
以下是在 8xB200 硬件上,针对 DS-R1 模型的最大吞吐量和最小延迟性能数据。
最大吞吐量 (Max-Throughput):
最小延迟 (Min-Latency):
只需几行代码即可开始使用 TensorRT LLM。
from tensorrt_llm._torch import LLM
llm = LLM(model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
outputs = llm.generate("Open the pod bay doors, HAL")
相关链接:
examples/pytorch/quickstart.py
examples/pytorch/quickstart_advanced.py
examples/pytorch/quickstart_multimodal.py
examples/mmlu_llmapi.py
更多关于新的基于 PyTorch 的 TensorRT-LLM 架构的技术细节,请观看以下视频。
开源一直是 TensorRT-LLM 的一个组成部分。
引入 TensorRT-LLM 的全新 GitHub-first 开发模型!
TensorRT-LLM 的更多部分已经开源
请遵循使用 TensorRT-LLM 的说明,并在 GitHub issues 上留下您的评论。
呼吁贡献(您将获得 TensorRT-LLM 团队的支持,将您的贡献引入 GitHub 仓库)。
重要文档
TensorRT-LLM Documentation
Building from source Code on Linux
How to run TRT-LLM tests
步骤 1: 创建一个 fork。访问 https://github.com/NVIDIA/TensorRT-LLM 并点击 "Fork"。
步骤 2: git clone --recursive [email protected]:user/TensorRT-LLM.git
步骤 3: 安装 git-lfs 并运行 git lfs install; git lfs pull
步骤 4: 创建一个开发分支: git checkout -b feature_xxx
步骤 5: 构建和安装 TensorRT-LLM 并进行您的修改。
步骤 6: 添加单元测试并测试您的修改。
步骤 7: 安装 pre-commit 并在您的修改上运行它: git add .; pre-commit
步骤 8: 推送您的修改并创建一个拉取请求(Pull Request)。
步骤 9: 一位 NVIDIA 工程师将被指派审查 PR 并启动 CI/CD。
步骤 10: 在 PR 被批准并通过 CI 后,一位 NVIDIA 员工会将其合并到主分支。
此部分内容通过视频形式提供了更多技术细节。视频标题为“TensorRT-LLM Goes GitHub-First”,由 Mayank Kaushik 和 Hao Lu 主讲,日期为 2025 年 4 月 30 日。
下表列出了即将举行的在线直播活动,涵盖了从 PyTorch 架构、社区贡献到具体模型(如 DeepSeek R1)性能优化等多个主题。
您可以在 TensorRT-LLM 的文档页面找到最新的技术博客和新闻。
技术博客 (Tech Blogs)
最新新闻 (Latest News)
下图展示了 TensorRT-LLM 在 2025 年 5 月至 7 月的路线图,涵盖了性能、用户与开发者体验、工作流与功能等方面的规划。
2025 年 5 月 (0.19)
- 性能: Data Parallel MLA, Eagle-MTP
- 用户与开发者体验: Open-sourced C++ runtime, [prototype] AutoDeploy for automatic model optimization
- 工作流与功能: DeepSeek v3, Customizable inference engine to Triton + TRTLLM-PyTorch example
2025 年 6 月 (0.20)
- 性能: Eagle 3 and other speculative decoding enhancements
- 用户与开发者体验: Reference disaggregated orchestrator built on top of trtllm-serve, Multi-modal embedding field with LLM API
- 工作流与功能: New models including Llama4, Qwen3, Gemma3, Dynasor-CoT and stream generation scaffolding for reasoning
2025 年 7 月+ (0.21+)
- 性能: Wide Expert Parallelism, Long context optimizations, NIXL integration (faster KV cache transfer with Dynamo)
- 用户与开发者体验: Fast load times via GDS for dynamic autoscaling, Stable LLM API with backward compatibility within major version, Full feature support + testing for core models GB200 NVL72 official support, Fast KV Cache offload to / retrieval from storage
- 工作流与功能: EPD disaggregation for multi-modal models, Accelerate reasoning trace generation in RL frameworks
注:路线图可能会变更,恕不另行通知。
最新的路线图和开发进展通过 GitHub 的 Issues 进行公开跟踪,方便社区了解各项功能的当前状态。
本次分享的核心要点包括: